package net.xinqushi.pthread.pthread;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class ThreadLockTest {
    // one thread can hold more locks
    public static void main(String[] args) {
        Lock lock1 = new ReentrantLock();
        Lock lock2 = new ReentrantLock();
        try{
            lock1.lock();
            System.out.println(Thread.currentThread()+" get lock1");

            //get lock2
            try{
                lock2.lock();
                System.out.println(Thread.currentThread()+" get lock2");
            }finally {
                lock2.unlock();
            }
        }finally {
            lock1.unlock();
        }

    }
}
